
function Montior(option){
	var _this = this; 
	this.internal = 1000;//间隔时间(ms)
	this.points = 7;//点数
	this.divSelector = "#machine";
	if(option && option.divSelector){
		this.divSelector = option.divSelector;
	}
	//java虚拟机
	this.jvmHeap = null;
	this.jvmNonHeap = null;
	this.jvmCupInfo = null;
	this.jvmThreadInfo = null;
	//系统
	this.osMem = null;
	this.osCpu = null;
	this.osSwap = null;
	this.osDisk = null;

	this.init = function(){
		this.getHeap();
		this.getNonHeap();
		this.getCpu();
		this.getThreadInfo();
		
		this.getOsMem();
		this.getOsCpu();
		this.getOsSwap();
	}
	
	this.getOsMem = function(){
		
		return this.osMem = new Highchart(_this.divSelector+" .os_mem",{
			chart: {
	            type: 'areaspline',
	            marginRight: 10,
	        },
	        title: {
	            text: ""//'内存情况'
	        },
			exporting : {
				enabled : false
			}, 
	        xAxis: {
				type : 'datetime',
				dateTimeLabelFormats: {   
					second: '%H:%M:%S' 
	            }
			   ,tickInterval:_this.internal
			   ,tickLength:_this.points
	        },
	        yAxis: {
	            title: {
	                text: '空间大小(GB)'
	            }
	        },
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>内存大小: " + this.y+" GB";
				},
				shared: true,
				crosshairs : true,
	            valueSuffix: ' GB',
			},
	        credits: {
	            enabled: false
	        },
	        plotOptions: {
	            areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ { 
				name:"已使用",
				color:"#FF00FF",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			},{ 
				name:"共计",
				color:"#5CACEE",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			} ]
		    }).getTarget();
	}
	this.getDisk = function(disks,useddata,data){
		
		return this.osDisk = new Highchart(_this.divSelector+" .os_disk",{
			chart: {
	            type: 'column',
	            marginRight: 10,
	        },
	        title: {
	            text: ""//'磁盘情况'
	        },
			exporting : {
				enabled : false
			}, 
	        xAxis: {
	        	 categories: disks
	        },
	        yAxis: {
	            title: {
	                text: '空间大小(GB)'
	            }
	        },
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>内存大小: " + this.y+" GB";
				},
				shared: true,
				crosshairs : true,
	            valueSuffix: ' GB',
			},
	        credits: {
	            enabled: false
	        },
	        plotOptions: {
	            areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            column: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ { 
				name:"已使用",
				color:"#FF00FF",
				data : useddata
			},{ 
				name:"共计",
				color:"#5CACEE",
				data : data 
			} ]
		    }).getTarget();
	}
	this.getOsSwap = function(){
		
		return this.osSwap = new Highchart(_this.divSelector+" .os_swap",{
			chart: {
	            type: 'areaspline',
	            marginRight: 10,
	        },
	        title: {
	            text: ""//'交换空间情况'
	        },
			exporting : {
				enabled : false
			}, 
	        xAxis: {
				type : 'datetime',
				dateTimeLabelFormats: {   
					second: '%H:%M:%S' 
	            }
			   ,tickInterval:_this.internal
			   ,tickLength:_this.points
	        },
	        yAxis: {
	            title: {
	                text: '空间大小(GB)'
	            }
	        },
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>内存大小: " + this.y+" GB";
				},
				shared: true,
				crosshairs : true,
	            valueSuffix: ' GB',
			},
	        credits: {
	            enabled: false
	        },
	        plotOptions: {
	        	areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ { 
				name:"已使用",
				color:"#FF00FF",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			},{ 
				name:"共计",
				color:"#5CACEE",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			} ]
		    }).getTarget();
	}
	this.getOsCpu = function() {
		
		return this.osCpu = new Highchart(_this.divSelector+" .os_cupinfo",{
			chart: {
	            type: 'areaspline'
	        },
			title : {
				text : ""//'CPU 利用情况'
			},
			xAxis : {
				type : 'datetime',
				dateTimeLabelFormats: {   
					second: '%H:%M:%S' 
	            }
			   ,tickInterval:_this.internal
			   ,tickLength:_this.points
			},
			yAxis : {
	            allowDecimals:true,
	            max:100, // 定义Y轴 最大值  
	            min:0, // 定义最小值  
				title : {
					text : '利用率（%）'
				},
//			    labels : {
//			        formatter : function () {
//			            var strVal = this.value + '';
//			            if (strVal.indexOf('.') == -1) {
//			                return strVal + '.00';
//			            } else {
//			                var arr = strVal.split('.');
//			                if (arr[1].length == 2) {
//			                    return strVal;
//			                } else if(arr[1].length < 2){
//			                    return strVal + '0';
//			                }else{
//			                	return parseFloat(strVal.toFixed(2));
//			                }
//			            }
//			        }
//			    } ,
			}, 
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>利用率: " + this.y+"%";
				},
				crosshairs : true
			},
			legend : {
				enabled : false
			},
			exporting : {
				enabled : false
			},
	        plotOptions: {
	        	areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ {
				name:"CPU利用率",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			} ]
		}).getTarget();
	}
	this.getThreadInfo = function(){
		
		return this.jvmThreadInfo = new Highchart(_this.divSelector+" .threadinfo",{
			chart: {
	            type: 'spline',
	            marginRight: 10,
	        },
	        title: {
	            text: ""//'线程'
	        },
	        subtitle: {
	            text: null,
	        },
			exporting : {
				enabled : false
			}, 
	        xAxis: {
				type : 'datetime',
				dateTimeLabelFormats: {   
					second: '%H:%M:%S' 
	            }
			   ,tickInterval:_this.internal
			   ,tickLength:_this.points
	        },
	        yAxis: {
	            title: {
	                text: '数量'
	            }
	        },
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>数量: " + this.y;
				},
				shared: true,
				crosshairs : true
			},
	        credits: {
	            enabled: false
	        },
	        plotOptions: {
	        	areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ { 
				name:"实时线程",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			},{ 
				name:"守护线程",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			}]
		    }).getTarget();
	}
	this.getCpu = function() {
		
		return  this.jvmCupInfo = new Highchart(_this.divSelector+" .cupinfo",{
	        chart: {
	            type: 'areaspline'
	        },
			title : {
				text : ""//'JVM CPU 利用情况'
			},
			xAxis : {
				type : 'datetime',
				dateTimeLabelFormats: {   
					second: '%H:%M:%S' 
	            }
			   ,tickInterval:_this.internal
			   ,tickLength:_this.points
			},
			yAxis : {
	            min:0, // 定义最小值  
				title : {
					text : '利用率（%）'
				},
	            plotLines: [{
	                value: 0,
	                width: 1,
	                color: '#808080'
	            }]
			}, 
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>利用率: " + this.y+"%";
				},
				crosshairs : true
			},
			legend : {
				enabled : false
			},
			exporting : {
				enabled : false
			},
	        plotOptions: {
	        	areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ {
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			} ]
		}).getTarget();
	}
	this.getHeap = function(){
		
		return this.jvmHeap = new Highchart(_this.divSelector+" .heap",{
			chart: {
	            type: 'areaspline',
	            marginRight: 10,
	        },
	        title: {
	            text: ""//'堆空间情况'
	        },
			exporting : {
				enabled : false
			}, 
	        xAxis: {
				type : 'datetime',
				dateTimeLabelFormats: {   
					second: '%H:%M:%S' 
	            }
			   ,tickInterval:_this.internal
			   ,tickLength:_this.points
	        },
	        yAxis: {
	            title: {
	                text: '空间大小(MB)'
	            }
	        },
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>空间大小: " + this.y+" MB";
				},
				shared: true,
				crosshairs : true,
	            valueSuffix: ' MB',
			},
	        credits: {
	            enabled: false
	        },
	        plotOptions: {
	        	areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ { 
				name:"已使用",
				color:"#FF00FF",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			},{ 
				name:"已分配",
				color:"#8B2323",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			},{ 
				name:"可分配最大值",
				color:"#5CACEE",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			} ]
		    }).getTarget();
	}
	this.getNonHeap = function(){
		
		return this.jvmNonHeap = new Highchart(_this.divSelector+" .nonheap",{
			chart: {
	            type: 'areaspline',
	            marginRight: 10,
	        },
	        title: {
	            text: ""//'非堆空间情况'
	        },
			exporting : {
				enabled : false
			}, 
	        xAxis: {
				type : 'datetime',
				dateTimeLabelFormats: {   
					second: '%H:%M:%S' 
	            }
			   ,tickInterval:_this.internal
			   ,tickLength:_this.points
	        },
	        yAxis: {
	            title: {
	                text: '空间大小(MB)'
	            }
	        },
			tooltip : {
				formatter : function() {
					return "时间: " + Highcharts.dateFormat('%H:%M:%S', this.x) + "<br/>空间大小: " + this.y+" MB";
				},
				shared: true,
				crosshairs : true,
	            valueSuffix: ' MB',
			},
	        credits: {
	            enabled: false
	        },
	        plotOptions: {
	        	areaspline: {
	                fillOpacity: 0.5,
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            },
	            spline: {
	                dataLabels: {
	                    enabled: true
	                },
	                enableMouseTracking: false
	            }
	        },
			series : [ { 
				name:"已使用",
				color:"#FF00FF",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			},{ 
				name:"已分配",
				color:"#8B2323",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			},{ 
				name:"可分配最大值",
				color:"#5CACEE",
				data : (function() {
					var data = [], time = (new Date()).getTime(), i;
					for (i = -_this.points; i <= 0; i++) {
						data.push({
							x : time + i * _this.internal,
							y : 0
						});
					}
					return data;
				})()
			} ]
		    }).getTarget();
	}
}